package usaco.c2010.march.bronze;
import java.util.Scanner;

/*
 * p3600
 * USACO March 2010
 */

public class p3600 {

	static int G;
	static int[] num, c, w;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		G = scanner.nextInt();
		num = new int[G];
		c = new int[G];
		w = new int[G];
		for (int i=0;i<G;++i) {
			num[i] = scanner.nextInt();
			c[i] = scanner.nextInt();
			w[i] = scanner.nextInt();
		}
		
		for (int i=1000;i<=9999;++i) {
			boolean flag = true;
			for (int j=0;j<G;++j) {
				flag = match(i,num[j],c[j],w[j]);
				if (!flag) {
					break;
				}
			}
			if (flag) {
				System.out.println(i);
				return;
			}
		}
		
		System.out.println("NONE");
	}

	private static boolean match(int n, int g, int cp, int cn) {
		int[] num = extract(n);
		int[] guess = extract(g);
		for (int i=0;i<4;++i) {
			if (num[i] == guess[i]) {
				cp--;
				num[i] = guess[i] = -1;
			}
		}
		if (cp != 0) {
			return false;
		}
		else {
			for (int i=0;i<4;++i) {
				if (num[i] != -1) {
					for (int j=0;j<4;++j) {
						if (guess[j] != -1) {
							if (num[i] == guess[j]) {
								num[i] = guess[j] = -1;
								cn--;
							}
						}
					}
				}
			}
			
			if (cn != 0) {
				return false;
			}
			else {
				return true;
			}
		}
	}

	private static int[] extract(int n) {
		int[] res = new int[4];
		for (int i=3;i>=0;--i) {
			res[i] = n%10;
			n/=10;
		}
		return res;
	}

}
